package cn.edu.scau.cmi.maintain.controller;

import cn.edu.scau.cmi.ema.domain.Foodbatch;
import cn.edu.scau.cmi.ema.util.CmiHibernateProxyUtil;
import cn.edu.scau.cmi.front.controller.FrontCmiEmaController;
import cn.edu.scau.cmi.maintain.service.PictureMaintenceService;
import org.testng.annotations.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Iterator;
import java.util.Set;

/**
 * 原来是在测试源文件夹中的方法，简化起见，放到
 * 
 */

@Controller()

//@PropertySource(value = { "classpath:food2type.properties" })

public class MaintainFoodbatchController extends FrontCmiEmaController {
	
	@Autowired
	PictureMaintenceService testPictureService;

	
	@RequestMapping(value = "/updateNameByFoodName", method = RequestMethod.GET)
	@ResponseBody
	@Transactional
	@Test
	@SuppressWarnings("unused")
	public void updateNameByFoodName () throws Exception {
		Set<Foodbatch> foodbatchs = foodbatchDAO.findAllFoodbatchs();
		Iterator<Foodbatch> foodbtachsIterator = foodbatchs.iterator();
		while (foodbtachsIterator.hasNext()) {
			Foodbatch foodbatch = foodbtachsIterator.next();
			Foodbatch foodbatch2 = CmiHibernateProxyUtil.deproxy(foodbatch);
			
			foodbatch.setName(foodbatch2.getFood().getName());
			System.out.println(foodbatch2.getName() + "已经修改！！！");
		}
	}
}